package com.glory.eapequipmentmonitor.utils;

import com.glory.eapequipmentmonitor.base.Constant;
import com.glory.eapequipmentmonitor.bean.BaseResponseBean;
import com.glory.eapequipmentmonitor.bean.RequestHeaderBean;
import com.glory.eapequipmentmonitor.bean.ResponseQueryBean;
import com.google.gson.Gson;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_NetUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hx
 * @date 2019/6/17
 * @desc
 */
public class NetUtils {
    public static void requestWithNormalCallBack(String method, JSONObject map, FreeUI_EntityCallBack<BaseResponseBean<?>> callBack) {
        FreeApi_NetUtils.requestGetNet(Constant.REQUEST_URL, method, getRequestMap(map, method), callBack);
    }

    public static Map<String, String> getRequestMap(JSONObject bodyMap, String method) {
        Map<String, String> map = new HashMap<>();
        map.put("requestMessage", getRequestJson(new RequestHeaderBean(method, Constant.CURRENT_USER), bodyMap));
        map.put("senderId", "EAP2MESSender");
        map.put("timeOut", "5000");
        return map;
    }

    public static String getRequestJson(RequestHeaderBean headerEntity, JSONObject bodyMap) {
        JSONObject jsonObject1 = new JSONObject();
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject1.put("Header", new JSONObject(new Gson().toJson(headerEntity)));
            jsonObject1.put("Body", bodyMap);
            jsonObject.put("Request", jsonObject1);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject.toString();
    }

    public static void requestQueryLot(JSONObject map, FreeUI_EntityCallBack<BaseResponseBean<ResponseQueryBean>> callBack) {
        FreeApi_NetUtils.requestGetNet(Constant.REQUEST_URL, "MES.LOTQUERY", getRequestMap(map, "MES.LOTQUERY"), callBack);
    }

    public static void requestNoResponse(JSONObject map, String method,FreeUI_EntityCallBack<BaseResponseBean<?>> callBack) {
        FreeApi_NetUtils.requestGetNet(Constant.REQUEST_URL, method, getRequestMap(map, method), callBack);
    }

}
